package concurrency.chapter5;

import java.util.Optional;
import java.util.stream.IntStream;

public class ThreadJoin2 {
    public static void main(String[] args) throws Exception {
        Thread t1 = new Thread(() -> {
            try {
                System.out.println("t1 is running");
                Thread.sleep(10_000);
                System.out.println("t1 is done");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        t1.start();
        t1.join(100, 10);//t1执行100毫秒10纳秒后，执行main线程

        Optional.of("All of tasks finish done").ifPresent(System.out::println);

        //Thread.currentThread().join();//死循环，当前线程是main在等main线程结束
    }
}
